package network;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Address {
    public static void main(String[] args) {
        try {
            InetAddress address = InetAddress.getByName("www.baidu.com");
            String ip = address.toString().split("/")[1];
            System.out.println("ip = " + ip);
            InetAddress addr = InetAddress.getByName(ip);
            System.out.println("hostname = " + addr.getHostName());
            System.out.println("localhost = " + InetAddress.getLocalHost());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
